/*File contains the timer code for the msg life time timer.*/
#include"projectHeader.h"

void* msgLifeTimeTimer(void*)
{

	while(1)
	{
		map<string,msgLifeTimeClass> ::iterator UOIDMsgLifeTimeMapIt;

		pthread_mutex_lock(&UOIDMsgLifeTimeMapMutex);
		for(UOIDMsgLifeTimeMapIt=UOIDMsgLifeTimeMap.begin();UOIDMsgLifeTimeMapIt!=UOIDMsgLifeTimeMap.end();UOIDMsgLifeTimeMapIt++)
		{
			int timer=((*UOIDMsgLifeTimeMapIt).second).msgLifeTimeValue;
			if(timer==1)
			{
				UOIDMsgLifeTimeMap.erase(UOIDMsgLifeTimeMapIt);
			}
			else
			{
				timer-=1;
				((*UOIDMsgLifeTimeMapIt).second).msgLifeTimeValue=timer;
			}
		
		}
		pthread_mutex_unlock(&UOIDMsgLifeTimeMapMutex);
		usleep(1000000);
		
	}

	pthread_exit(NULL);
}
